<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>layui</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">

	<link href="../../static/font-awesome-4.7.0/css/font-awesome.min.css" rel="stylesheet">
	<link rel="stylesheet" href="../../static/vui/css/vui.css">
	<script type="text/javascript" src="../../static/js/jquery-1.9.1.min.js"></script>
	<script type="text/javascript" src="../../static/layer/layer.js"></script>
	<script type="text/javascript" src="../../static/js/common.js"></script>
	<script type="text/javascript" src="../../static/vui/js/datagrid.js"></script>

</head>
<body>

<div>

	<div id="formArea">
		<table class="table-top">
			<tr>
				<td>
					<input type="text" class="input" name="complex" placeholder="批次号模糊查询" autocomplete="off"/>
				</td>
				<td>
					<button class="button" id="query"><span>查询</span></button>
					<button class="button" id="reset"><span>重置</span></button>
				</td>
			</tr>
		</table>
	</div>

	<div style="margin-top:-10px;">
		<div id="table"></div>
	</div>
</div>
<script>
    var params = app.getRequestParams();
    $(function(){
        $('#table').datagrid({
            simplePagination:true,
            width:580,limit:8,limits:[8],
            url:app.BASE_API_URL+'order/batchPage',
            queryParams:{productId:params.productId},
            dblClickRow:selectRow,
            columns:[
                {field:'batchNo',title:'批次号',width:160,formatter:function (row) {
                        return '<a href="javascript:selectRow(\''+row.batchNo+'\','+row.productDate+');" class="link">'+row.batchNo+'</a>';
                    }},
                {field:'productDate',n:'date',title:'生产日期',width:80},
                {field:'endDate',title:'有效期至',width:80,formatter:function (row) {
                    return app.time2str(app.add(row.productDate,app.mul(row.fineDays , 86400000)));
                }},
                {field:'fineDays',title:'保质期',width:160}
            ]
        });

        $('#query').click(function () {
            queryProduct();
        });

        $('#reset').click(function () {
            $('input[name="complex"]').val('');
        });

    });

    function selectRow(value,productDate) {
        parent.$('#'+params.searchId).parent().parent().find('.vui-table-cell[field="productionDate"]').html(app.time2str(productDate));
        parent.$('#'+params.searchId).parent().html(value);
        app.closeLastWindow();
    }

    function queryProduct(customerTypeLogicalCode) {
        var queryParams = app.serializeForm();
        queryParams.customerTypeLogicalCode = customerTypeLogicalCode;
        $("#table").datagrid("reload",queryParams);
    }
</script>
</body>
</html>